package com.itheima.response;

import com.oracle.tools.packager.IOUtils;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;

/*
    响应图片到浏览器
 */
@WebServlet("/servletResponseDemo2")
public class ServletResponseDemo2 extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取文件在服务器的输入流对象
        InputStream is = getServletContext().getResourceAsStream("/img/zyx.jpg");

        // 获取字节输出流
        ServletOutputStream outputStream = resp.getOutputStream();

        // IO流对拷
        org.apache.commons.io.IOUtils.copy(is,outputStream);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
